﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PriceEdit.aspx.cs" Inherits="Admin_PriceEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="../css/main-admin.css" rel="stylesheet" type="text/css" />

    <script src="../Jscript/jquery-1.3.2.min.js" type="text/javascript"></script>

    <script src="../Jscript/page.js" type="text/javascript"></script>

    <style type="text/css">
        .slist
        {
            width: 110px;
            border: 1px solid #CCC;
            height: 20px;
            margin-right: 10px;
        }
    </style>
	



    <script type="text/javascript">
        $(document).ready(function() {



              <%=ajax %>
              });
        function ToSet(tp) {
            var v = $("." + tp + ":first").val();
            $("." + tp).val(v);
            ToEditAll();
        }
        function ToEditAll() {
            $(".noname").each(function() {
                countpay($(this).html());
            });

        }



        //代购费=垫付费用*5%
        function countpay(no) {




            //重量收费
            
            
            var ow = $("#weight" + no).val();
            var tw= $("#dw" + no).attr("title");
            if(tw=="")
            {
            tw=1;
            }
            
                     var weight = 0
                     if(parseFloat2(ow)>parseFloat2(tw))
                     
                     {
                     weight=parseFloat2(ow);
                     }
                     else
                     {
                       weight=parseFloat2(tw);
                     }
                     
                     
      $("#pw" + no).attr("title",weight);      
    
      
  
            var zlsf = 0;
            if (weight > 0) {
                //   var value = $(".slist" + no + " option:selected").val();

                var value = $("select[title='" + no + "']   option:selected").val();
                if (value == "") {
                    OpenWindow('计费类别异常');
                    return;
                }
                var sb = "";
                var f = value.indexOf(",");
                var e = value.lastIndexOf(",")


                var sb = value.substring(f + 1, e);
                var cb = value.substring(e + 1);



               if (weight > 4) {

                var cbw = (weight) * cb;
                 zlsf = changeTwoDecimal_f(cbw);
                 }
                 else
                 {
                var cbw = (weight - 1) * cb;
                 zlsf = changeTwoDecimal_f(parseFloat2(sb) + cbw);
                 }

                $("#payweight" + no).html(zlsf);
            }


            //代购费
            var daigou = 0;
            //包装费
            var baozhuang = 0;

            var allbz = $("#spid" + no).attr("title");
            if (allbz != ",") {

                //  daigou=allbz.re
                var fs = allbz.indexOf(",");

                baozhuang = allbz.substring(0, fs);
                daigou = allbz.substring(fs + 1, allbz.length);

                //  alert(daigou + "--" + baozhuang);
                //  return;
            }
            else {

                alert("当前客户未设置代购费率，包装费");
                return;
            }

            //            alert(daigou + "--" + baozhuang);
            //垫付费计算
            var DFF = changeTwoDecimal_f($("#dianfufei" + no).val() * daigou * parseFloat2(0.01));
            $("#dgflb" + no).html(DFF);


            //包装费计算

            var Baozhaungfei = changeTwoDecimal_f(weight* baozhuang);

            $("#baozhuang" + no).html(Baozhaungfei);
            var all = parseFloat2(DFF) + parseFloat2(Baozhaungfei) + parseFloat2(zlsf) + parseFloat2($("#dianfufei" + no).val()) + parseFloat2($("#baoxianfei" + no).val()) + parseFloat2($("#guansui" + no).val()) + parseFloat2($("#qitafei" + no).val());


            var ok = parseFloat2($("#youhui" + no).val());

       //  alert(all + "---" + ok + "-" + DFF + "-" + Baozhaungfei + "--" + zlsf);



            var nowall = 0;
            if ((all - ok) > 0) {
                nowall = all - ok;
            }
            $("#all" + no).html(nowall);


        }

        function parseFloat2(value) {
            var f_x = parseFloat(value);
            if (isNaN(f_x)) {
                return 0;
            }
            else {
                return f_x;
            }
        }


        function changeTwoDecimal(x) {
            var f_x = parseFloat(x);
            if (isNaN(f_x)) {

                alert('您输入数字有误，请输入数字');
                return false;
            }
            var f_x = Math.round(x * 100) / 100;

            return f_x;
        }
        function changeTwoDecimal_f(x) {
            var f_x = parseFloat(x);
            if (isNaN(f_x)) {

                alert('您输入数字有误，请输入数字');
                return false;
            }
            var f_x = Math.round(x * 100) / 100;
            var s_x = f_x.toString();
            var pos_decimal = s_x.indexOf('.');
            if (pos_decimal < 0) {
                pos_decimal = s_x.length;
                s_x += '.';
            }
            while (s_x.length <= pos_decimal + 2) {
                s_x += '0';
            }
            return s_x;
        }
        function Getid(Tno) {

            var value = $("select[title='" + Tno + "']   option:selected").val();
            var f = value.indexOf(",");
            return value.substring(0, f);
        }
        var boolok=0;
        function ToPost() {

            ToEditAll();
            var isep = "";
            var no = "";
            var weight = "";
            var paytype = "";
            var weightpay = "";
            var dianfu = "";
            var daigou = "";
            var baozhuang = "";
            var guansui = "";
            var baoxian = "";
            var qita = "";
            var youhui = "";
            var payweight="";

            $(".noname").each(function() {

                var newno = $(this).html()
                no = no + "," + newno;
                isep = isep + "," + $("#isepcss" + newno).html();
                weight = weight + "," + $("#weight" + newno).val();
                paytype = paytype + "," + Getid(newno);

                weightpay = weightpay + "," + $("#payweight" + newno).html();

                dianfu = dianfu + "," + $("#dianfufei" + newno).val();
                daigou = daigou + "," + $("#dgflb" + newno).html();
                baozhuang = baozhuang + "," + $("#baozhuang" + newno).html();

                guansui = guansui + "," + $("#guansui" + newno).val();

                baoxian = baoxian + "," + $("#baoxianfei" + newno).val();
                qita = qita + "," + $("#qitafei" + newno).val();
                youhui = youhui + "," + $("#youhui" + newno).val();
                payweight = payweight + "," +  $("#pw" + newno).attr("title");
				itsep = $("#isepcss" + newno).html();
				
				if (itsep != "Sep") {
				weight2 = $("#weight" + newno).val();
				trno = newno;
                 }

				
               
 
            });
			
			
          //  var id = window.document.getElementById("ow").value;



            OpenWindow("数据更新中，请稍后");

            $.get("ToPostPriceEdit.ashx", { sep: isep, pno: no, pweight: weight, ppaytype: paytype, pweightpay: weightpay, pdianfu: dianfu, pdaigou: daigou, pbaozhuang: baozhuang, pguansui: guansui, pbaoxian: baoxian, pqita: qita, pyouhui: youhui,ppayweight:payweight }, function(data) {


                ToAlet(data);
				
			 if (itsep != "Sep") {
            var url = "/admin/test/updatepage2.asp?weight=" + weight2 +"&trno=" + trno+"&itsep=" + itsep ;a
            window.open(url, 'new' ,'height=1, width=1');
			}

            });


        }

        function ToAlet(data) {
            if (data != "err") {
                OpenWindow(data);
                boolok=1;
            }
            else {
                OpenWindow("数据更新失败！请重试");

            }
        }
        function SetSelect(tno,text) {
        
            var count = $("select[title='" + tno + "']").length;
            
            for (var i = 0; i < 2; i++) {
            
                if ($("select[title='" + tno + "']").get(0).options[i].text == text) {
                
                    $("select[title='" + tno + "']").get(0).options[i].selected = true;
                 
                    break;
                }
                else
                {
                   
                }
            }
        }
        
        
         var newtage = "";
        function EditValue(tag) {


            newtage = tag
            ToPost();
            window.setInterval("ToUrl()", 500); //启动1秒定时 

        }


        function ToUrl() {
            if (boolok == 1) {
                var tnvalue = GetQueryString("no");
                if (tnvalue == "") {
                    alert("参数异常！请关闭重试！");
                }
                switch (newtage) {
                    case "name":
                        window.location = "NameEdte.aspx?no=" + tnvalue;
                        break;
                    case "logo":
                        window.location = "BillLogoPl.aspx?no=" + tnvalue;
                        break;
                    case "other":
                        window.location = "OtherEdit.aspx?no=" + tnvalue;
                        break;
                    case "price":
                        window.location = "PriceEdit.aspx?no=" + tnvalue;
                        break;


                }
            }

        }
        function GetQueryString(name) {

            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");

            var r = window.location.search.substr(1).match(reg);

            if (r != null) return unescape(r[2]); return null;

        }
		

			


    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div class="title" onclick="countdgf('3000000011')">
        批量价格编辑</div>
    <div class="trans-search-title">
        <div class="trans-edit-no">
            货运单号</div>
        <div class="trans-edit-weight">
            重量.磅
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('weight')" /></div>
        <div class="trans-edit-type">
            计费类别
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('slist')" /></div>
        <div class="trans-edit-charge">
            重量收费</div>
        <div class="trans-edit-prepay">
            垫付费用
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('dff')" /></div>
        <div class="trans-edit-buyfee">
            代沟费</div>
        <div class="trans-edit-packfee">
            包装费</div>
        <div class="trans-edit-duty">
            关税
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('gs')" /></div>
        <div class="trans-edit-insu">
            保险费
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('bxfei')" /></div>
        <div class="trans-edit-otherfee">
            其他费用
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('qita')" /></div>
        <div class="trans-edit-promo">
            优惠
            <img src="../images/arr-down-s.gif" width="13" height="13" align="absmiddle" onclick="ToSet('youhui')" /></div>
<div class="trans-edit-promo">
           </div>
    </div>
    <asp:Repeater ID="list" runat="server">
        <ItemTemplate>

            <%#Eval("Sep").ToString() == "234" ? "<div  id=\"div" + Container.ItemIndex + "\"  class=\"trans-edit-line\" style=\"background-color:#cccccc\">" : "<div   id=\"div" + Container.ItemIndex + "\"  class=\"trans-edit-line\">"%>
            <div class="trans-edit-no">				
                <strong style="color: Red">
                    <%# Container.ItemIndex+1 %>
                </strong><span id='isepcss<%#Eval("TrackingNo")%>' style="color: Red">
                    <%#Eval("Sep").ToString() == "True"?"Sp":""%></span> <a href="">
                        <asp:Label ID="no_txt" Text='<%#Eval("TrackingNo")%>' runat="server" CssClass="noname"></asp:Label></a>
                <span title='<%#GetPrice(Eval("CreateUserID"))%>' id='spid<%#Eval("TrackingNo")%>'>
                </span><span title='<%#Eval("DimensionsWeight")%>' id='dw<%#Eval("TrackingNo")%>'>
                </span><span title='<%#Eval("ChargedWt")%>' id='pw<%#Eval("TrackingNo")%>'>
                
                </span>
            </div>
            <div class="trans-edit-desp"><%#GetName(Eval("TrackingNo").ToString())%></div>
            <div style="height: 8px; width: 960px; float: left;">
            </div>
            <div class="trans-edit-no">
                总价: $<span id="all<%#Eval("TrackingNo")%>"><%#Eval("Total")%></span></div>
          <div class="trans-edit-weight">
                <input type="text" name="textfield2" id="weight<%#Eval("TrackingNo")%>" value='<%#Eval("TotalWeight") %>'
                     onclick="CopyInfo()" onchange="javascript:countpay('<%#Eval("TrackingNo")%>')" class="weight" style="width: 40px;
                    border: 1px solid #CCC; height: 15px;" />
              磅
              
          </div>
            <div class="trans-edit-type">
                <asp:DropDownList ID="ShowType" runat="server" class='slist' DataTextField="Name"
                    ToolTip='<%#Eval("TrackingNo")%>' DataValueField="cid" DataSource='<%#GetType(Eval("CreateUserID"),Eval("TrackingNo"),Eval("Memo1"))%>'>
                </asp:DropDownList>
				
                </select> 
            </div>
            <div class="trans-edit-charge">
                <span id='payweight<%#Eval("TrackingNo")%>'>
                    <%#Eval("FreightCharge")%>
                </span>&nbsp;
            </div>
            <div class="trans-edit-prepay">
                $
                <input type="text" name="textfield2" id="dianfufei<%#Eval("TrackingNo")%>" onchange="javascript:countpay('<%#Eval("TrackingNo")%>')"
                    class="dff" style="width: 60px; border: 1px solid #CCC; height: 15px;" value='<%#Eval("Memo2") %>' /></div>
            <div class="trans-edit-buyfee">
                &nbsp; <span id='dgflb<%#Eval("TrackingNo")%>'>
                    <%#Eval("Memo3") %></span>
            </div>
            <div class="trans-edit-packfee">
                &nbsp; <span id='baozhuang<%#Eval("TrackingNo")%>'>
                    <%#Eval("Memo4") %></span>
            </div>
            <div class="trans-edit-duty">
                $
                <input type="text" name="textfield2" id="guansui<%#Eval("TrackingNo")%>" value='<%#Eval("Duties") %>'
                    onchange="javascript:countpay('<%#Eval("TrackingNo")%>')" runat="server" class="gs"
                    style="width: 60px; border: 1px solid #CCC; height: 15px;" /></div>
            <div class="trans-edit-insu">
                $
                <input type="text" name="textfield2" id="baoxianfei<%#Eval("TrackingNo")%>" value='<%#Eval("Premium") %>'
                    onchange="javascript:countpay('<%#Eval("TrackingNo")%>')" class="bxfei" style="width: 60px;
                    border: 1px solid #CCC; height: 15px;" /></div>
            <div class="trans-edit-otherfee">
                $
                <input type="text" name="textfield2" id="qitafei<%#Eval("TrackingNo")%>" value='<%#Eval("OtherCharge") %>'
                    onchange="javascript:countpay('<%#Eval("TrackingNo")%>')" class="qita" style="width: 60px;
                    border: 1px solid #CCC; height: 15px;" /></div>
            <div class="trans-edit-promo">
                -$
                <input type="text" name="textfield2" id="youhui<%#Eval("TrackingNo")%>" class="youhui"
                    onchange="javascript:countpay('<%#Eval("TrackingNo")%>')" value='<%#Eval("Memo5") %>'
                    style="width: 60px; border: 1px solid #CCC; height: 15px; color: #F00;" />
            </div>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    <div style="color: #606; font-weight: bold; float: left; width: 966px; margin-top: 20px;
        text-align: center;">
        <div style="width: 100%; text-align: right">
            <div style="margin: 10px 0px 0px 3px;">
                <img src="../images/arrow-up.gif" width="25" height="24" />
                &nbsp;
                <img src="../images/btn-itemlot.gif" width="68" height="25" border="0" onclick="EditValue('name')" />
                &nbsp;
                <img src="../images/btn-otherlot.gif" width="68" height="25" border="0" onclick="EditValue('other')" />
                &nbsp;
                <img src="../images/btn-pringlogolot.gif" width="68" height="25" border="0" onclick="EditValue('logo')" />
                &nbsp;&nbsp;
            </div>
        </div>
        <img src="../images/btn-save-trans.gif" width="192" height="40" onclick="ToPost()" />
    </div>
    </form>
</body>
</html>
